package cn.hill4j.tool.spring.std.advice.controller;

import cn.hill4j.tool.spring.ext.feign.wrap.WrapFeignUtils;
import cn.hill4j.tool.spring.std.advice.feign.SayHelloFeign;
import cn.hill4j.tool.spring.std.advice.feign.WrapFeignClient;
import cn.hill4j.tool.spring.std.advice.mvc.annotation.MvcConverter;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDateTime;

@RestController
@RequestMapping("/say")
public class SayHelloController {
    @Resource
    private SayHelloFeign sayHelloFeign;
    @Resource
    private WrapFeignClient wrapFeignClient;
    @GetMapping("/hello/{user}")
    public String sayHello(@PathVariable("user")String user){
        return LocalDateTime.now() + " hello :" + user;
    }
    @PostMapping("/jsonHello")
    @MvcConverter
    public String sayJson(@RequestBody String data){
        return LocalDateTime.now() + " hello :" + data;
    }

    @GetMapping("/feignHello/{user}")
    public String feignHello(@PathVariable("user")String user){
        return sayHelloFeign.sayHello(user);
    }


    @GetMapping("/hello/{port}/{user}")
    public String sayHello(@PathVariable("port")String port,@PathVariable("user")String user){
        return WrapFeignUtils.wrapInvokeFeign(() -> wrapFeignClient.sayHello(user),port);
    }

}
